import { reqAddShopCart, reqGetGoodInfo } from "@/api";

const state = {
    goodsInfo: {}
};
const actions = {
    async getGoodsInfo({ commit }, goodId) {
        let result = await reqGetGoodInfo(goodId);
        if (result.code == 200) {
            commit("GETGOODINFO", result.data)
            return 'ok'
        } else {
            return Promise.reject(result.msg)
        }
    },
    async addShopCart({ commit }, goodItem) {
        let result = await reqAddShopCart(goodItem);
        if (result.code == 200) {
            return "ok";
        } else {
            return Promise.reject(result.msg);
        }
    }
};
const mutations = {
    GETGOODINFO(state, { good }) {
        state.goodsInfo = good;
    }
};
const getters = {
    goodName(state) {
        return state.goodsInfo.goodsName;
    }
};

export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}